﻿using Abp.Runtime.Validation;
using NetCore.CustomAttributes;
using NetCore.Extensions;
using System.ComponentModel;
using System.IO;

namespace NetCore.Dtos
{
    /// <summary>
    /// 基础附件类
    /// </summary>
    [Description("基础附件类")]
    public abstract class BaseAttachmentDto : BaseDto
    {
        /// <summary>
        /// 文件顺序
        /// </summary>
        [Description("文件顺序")]
        public decimal? Order { get; set; }
        /// <summary>
        /// 图片扩展名规则
        /// </summary>
        [Description("图片扩展名规则"), NotSet]
        private string _extensions = ".jpg.jpeg.png.gif.bmp.tiff";
        /// <summary>
        /// 文件绝对路径
        /// </summary>
        [Description("文件全名")]
        public string FilePath { get; set; }
        /// <summary>
        /// 前端虚拟路径
        /// </summary>
        [Description("前端虚拟路径")]
        public string VirtualPath { get; set; }
        /// <summary>
        /// 文件名(包含扩展名)
        /// </summary>
        [Description("文件名"), NotSet]
        public string FileName => FilePath.HasValue() ? Path.GetFileName(FilePath) : string.Empty;

        /// <summary>
        /// 文件名(不含文件名)
        /// </summary>
        [Description("文件名"), NotSet]
        public string FileNameWithoutExtension => FilePath.HasValue() ? Path.GetFileNameWithoutExtension(FilePath) : string.Empty;
        /// <summary>
        /// 扩展名
        /// </summary>
        [Description("扩展名"), NotSet]
        public string Extention => FilePath.HasValue() ? Path.GetExtension(FilePath)?.ToLower() : string.Empty;

        /// <summary>
        /// 是否图片文件
        /// </summary>
        [Description("是否图片"), NotSet]
        public bool IsImage => Extention.HasValue() && _extensions.Contains(Extention);


        public override void AddValidationErrors(CustomValidationContext context)
        {
            //if (!Phone.Validate())
            //{
            //    context.Results.Add(new ValidationResult("请输入正确的电话号码!"));
            //}
        }
    }
}
